#!/bin/bash

## @Version	1.0
## @Author	Fabio Grucci (alias Phoenix)
## @License	LGPL

## This script map file ".asl" into ".pls" and convert file path from windows to linux
## This script must be personalized with your mount point: see "gsub()" method

HELP="usage <./asl2pls.sh FILE.asl>\nresult: print on std_out a file \".pls\"\n"

if [ $1="?" -o $1="-?" -o $1="/?" -o $1="help" -o $1="-help" -o $1="--help" ]; then
	echo -e $HELP;
	exit 0;
fi;

FILE_LIST=`cat "$1" | grep -v ALSONG | awk -v FS="|" -v RS="\n" '{print $5}'`;

FILE_NUM=`echo "$FILE_LIST" | wc -l`;

echo "$FILE_LIST" | awk -v FS="" -v RS="\n" -v F_NAME="$1" -v FILE_NUM="$FILE_NUM" 'BEGIN{
			print "[playlist]";
			print "X-GNOME-Title=Coda di riproduzione da " F_NAME;
			print "NumberOfEntries="FILE_NUM;
		}
		{
			gsub(/D:\\/, "/media/dati/");
			gsub(/X:\\/, "/media/dati_stabili/");

			gsub(/\\/, "/");
			gsub(/ /, "%20");
			gsub(/\[/, "%5B"); gsub(/\]/, "%5D");
			print "File" NR "=file://" $0;
		}'

